﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Clipper.Model.DataBaseModel;

namespace Clipper.BLL.DataBaseBLL
{
    public class LocaltionPosition
    {
        Clipper.DAL.LocaltionPosition localModelDal = new DAL.LocaltionPosition();
        /// <summary>
        /// 更新数据存储表格
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Update(Clipper.Model.DataBaseModel.LocationPosition model)
        {
            return localModelDal.Update(model);
        }

        public Clipper.Model.DataBaseModel.LocationPosition GetModel(string place)
        {
            return localModelDal.GetModel(place);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public ObservableCollection<Clipper.Model.DataBaseModel.LocationPosition> GetModelList(string strWhere)
        {
            DataSet ds = localModelDal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }


        /// <summary>
        /// 表格解析方法
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        private ObservableCollection<LocationPosition> DataTableToList(DataTable dt)
        {

            ObservableCollection<Clipper.Model.DataBaseModel.LocationPosition> modelList = new ObservableCollection<Clipper.Model.DataBaseModel.LocationPosition>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Clipper.Model.DataBaseModel.LocationPosition model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = localModelDal.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        //model.DetectVariety = mdetectVarietyDal.GetModel(model.DetectVarietyID);
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }
    }
}
